import $app from '../$app';
import $router from '@/router'


// 专利申请人-费减资料-上传的内容
let info_edit_do = {
	//修改商标订单-带出商标详情
	tmEditGlobe(that) {
		let {
			orderInfo: {
				type,
				upload_type,
				name,
				img_path,

				//肖像权
				is_portrait, //是否以肖像作为商标申请注册,false否,true是
				portrait_path,

				// 商标说明
				remark,
			}
		} = that;

		

		if ($router.history.current.query.type == 200) { //正常流程注册
			// 商标信息 ok
			that.$refs['B1'].xTlex = type;

			that.$refs['B1'].zName1=((type==1)?name:'');
			that.$refs['B1'].xPiw=upload_type;
			that.$refs['B1'].img_path = img_path;

			//肖像权
			that.$refs['B1'].is_portrait = is_portrait;
			that.$refs['B1'].portrait_path = portrait_path;

			that.$refs['B1'].remark = remark; //商标说明

		} else if ($router.history.current.query.type == 209) { //担保注册
			// 商标信息 ok
			that.$refs['B3'].xTlex = type;

			that.$refs['B3'].zName1=((type==1)?name:'');
			that.$refs['B3'].xPiw=upload_type;
			that.$refs['B3'].img_path = img_path;
			
			that.$refs['B3'].remark = remark; //商标说明

			// 针对担保注册，特有定制这句话，一旦下单后，商标名称就不给你二次修改，因为是担保。
			that.$refs['B3'].zNameShow = false;

		}

		//申请人信息 ok
		let {
			orderInfo,
			orderInfo: {
				reg_people_type,
				reg_people_name, //名

				idcard_path, //身份证复印件 地址 pdf
				idcard_img_path, //身份证复印件 地址 图片

				business_license_path, //营业执照 pdf
				business_license_img_path, //营业执照 图片

				attorney_path,

				business_license_number,
				idcard,

				business_license_province,//省份名称 中文汉字
				business_license_province_code,//省份代码
				business_license_city,//城市名称 中文汉字
				business_license_city_code,//城市代码
				business_license_detail_address,//地址(短地址)
				business_license_address//地址(总拼接长地址)
			}
		} = that;


		that.$refs['B2'].reg_people_type = reg_people_type; //1企业 2个体工商
		that.$refs['B2'].reg_people_name = reg_people_name; //名

		that.$refs['B2'].attorney_path = attorney_path; //委托书

		// pdf
		that.$refs['B2'].business_license_path = business_license_path; //上传营业执照
		that.$refs['B2'].idcard_path = idcard_path; //身份证

		// 图片
		that.$refs['B2'].business_license_img_path = business_license_img_path; //上传营业执照
		that.$refs['B2'].idcard_img_path = idcard_img_path; //身份证
		
		that.$refs['B2'].business_license_number = business_license_number;
		that.$refs['B2'].idcard = idcard;

		//只有新数据会有以下字段
		if(business_license_province_code){//有省代码一定是新数据
			that.$refs['B2'].business_license_province = business_license_province; 
			that.$refs['B2'].business_license_province_code = business_license_province_code; 
			that.$refs['B2'].business_license_city = business_license_city; 
			that.$refs['B2'].business_license_city_code = business_license_city_code; 
			that.$refs['B2'].business_license_detail_address = business_license_detail_address; 
			//执行一般城市列表 赋值，演示执行更优秀
			setTimeout(()=>{
				that.$refs['B2'].business_license_province_code_Fun();	
			},105);
		}else{
			that.$refs['B2'].business_license_detail_address = business_license_address; 
			// 旧数据提示语
			$app.alert('系统数据格式更新，请完善省市区地区','温馨提示',()=>{
				that.$refs["B2"].$refs['business_license_detail_address'].focus();
			});
		}
		


	},
	
	//修改专利订单
	patentTim(that) {

		let {
			orderInfo: {
				order_id,
				state,
				
				applicant_list,//申请人 列表
				inventor_list,//发明人 列表
				patent_file_path,
				is_cost_reduction,
				same_day,
				is_early_release,
				instruction_path,
				instruction_abstract_path,
				claims_path,
				instruction_image_path,
				abstract_image_path,
				abstract_image_index,
				claims_item_count,
				appe_brief_desc_path,
				appe_img_list,

				other_tool_show,
				priority_declar_list,
				main_applicant,
				div_app_number,
				case_div_app_number,
				div_app_date,
				other_one,
				other_two,
				other_three,
				preserve_data,
				similar_design,
				complete_product,
				preserve_is_dna,
				preserve_is_genetic,
			},
			orderInfo,
			$route: {
				query: {
					type
				}
			}
		} = that;




		//订单详情
		$ajax.orderInfo(order_id, resData => {
			// 右上角名字赋值
			that.$refs['baseTop'].goodsName = resData.goods_name;

			//备注
			if ($app.judgeData(resData.remark)) {
				that.remark = resData.remark;
			}
		});

		


		//1 或 2 才能修改
		if (state == 1 || state == 2) {


			//baseTop 赋值
			info_edit_do.baseTop_to_Fun(that,orderInfo);


			// 申请人赋值
			info_edit_do.applicant_list_Fun(that,applicant_list);
			
			//发明人赋值
			info_edit_do.FMR_array_Fun(that,inventor_list);


			//实用新型 发明
			if (type == 100 || type == 102) {
				that.$refs['middle'].patent_file_path = $app.getVal_filePath(patent_file_path);
				that.$refs['middle'].is_cost_reduction = is_cost_reduction;
				that.$refs['middle'].same_day = same_day;
				that.$refs['middle'].is_early_release = is_early_release;
				that.$refs['middle'].five_books = {
					instruction_path,
					instruction_abstract_path,
					claims_path,
					instruction_image_path,
					abstract_image_path
				};

				that.$refs['middle'].abstract_image_index = abstract_image_index;
				that.$refs['middle'].claims_item_count = claims_item_count;


			} else { //外观
				that.is_cost_reduction = is_cost_reduction; //请求费减且已完成费减资格备案
				that.appe_brief_desc_path = appe_brief_desc_path; //外观简要说明书
				that.appe_img_list = appe_img_list;

			}

			//底部其他 other
			if ($app.judgeData(that.$refs['other'])) {
				
				// 优先权声明 - 有值
				if($app.judgeData(priority_declar_list)){
					that.$set(that.$refs['other'].$refs['PDList'],'priority_declar_list',priority_declar_list);
				}


				// 生物材料样品 - 有值
				if($app.judgeData(preserve_data)){
					
					//Checkbox 只认布尔值，把0和1转成，布尔值
					if (preserve_data.preserve_is_life == 1) {
						preserve_data.preserve_is_life = true;
					} else {
						preserve_data.preserve_is_life = false;
					}

					that.$set(that.$refs['other'],'preserve_data',preserve_data);
				}
				
				that.$refs['other'].other_tool_show = other_tool_show;
				that.$refs['other'].main_applicant = main_applicant;
				that.$refs['other'].div_app_number = div_app_number;
				that.$refs['other'].case_div_app_number = case_div_app_number;
				that.$refs['other'].div_app_date = div_app_date;
				that.$refs['other'].other_one = other_one;
				that.$refs['other'].other_two = other_two;
				that.$refs['other'].other_three = other_three;
				that.$refs['other'].similar_design = similar_design;
				that.$refs['other'].complete_product = complete_product;
				that.$refs['other'].preserve_is_dna = preserve_is_dna;
				that.$refs['other'].preserve_is_genetic = preserve_is_genetic;
			}

		} else {
			$app.toast('该订单不能修改', false, () => {
				$app.closeTag($router.history.current) // 关闭本页面
			})
		}



	},
	// 专利申请-回填-资料赋值，发明人， 有两个地方专用，其他地方慎用
    FMR_array_Fun(that,inventor_list){

		
        // 发明人
        if ($app.judgeData(inventor_list)) {
			that.$set(that.$refs['common'],'inventor_list',inventor_list);
        }
	},
	
	// baseTop 专利详情-订单数据-回来-赋值
	baseTop_to_Fun(that,orderInfo){
		let {
			order_id,
			name,//专利名称
			attorney_path,//代理委托书 原
			attorney_path1,//代理委托书 P过章
			attorney_name_list,//代理人
		}=orderInfo;
		that.$refs['baseTop'].order_id = order_id;
		$app.judgeData(name) && (that.$refs['baseTop'].zName1 = name); //专利名字
		$app.judgeData(attorney_name_list) && (that.$refs['baseTop'].attorney_name_list = attorney_name_list); //代理人
		if($app.judgeData(attorney_path)){//代理委托书
			if($app.judgeData(attorney_path1)){//代理委托书 P过章
				that.$set(attorney_path,'file_path1',$app.getVal_filePath(attorney_path1) );
				that.$set(attorney_path,'file_url1',$app.getVal_fileUrl( attorney_path1) );
			}
			console.log('代理委托书 合体 = ',attorney_path);
			that.$refs['baseTop'].attorney_path=attorney_path; //赋值
		}
	}, 

    
    // 专利申请-回填-资料赋值，申请人， 有两个地方专用，其他地方慎用
    applicant_list_Fun(that,applicant_list){
        if ($app.judgeData(applicant_list)) {

			(that.$refs['common'].applicant_list)=[];//清空数据

			let old_data=false;

            applicant_list.forEach((val, i) => {
				// 只有中国才有省市区
				if(val.nationality=='CN'){
					// 有省 代码 新数据
					if($app.judgeData(val.province_code)){
					
						// 专利 地区联动=》取一次select框列表
						// $ajax.cpcAreaList(val.province_code,resData=>{
							that.$set(val, "cityList",[]);//赋值 市列表
							info_edit_do.china_Pai(that,applicant_list,val);
						// });
						
					}else{//老数据
						old_data=true;
	
						// 用新方式 ，把老地址，赋值到，新地址
						if(!$app.judgeData(val.biz_nationality)){
							val.biz_nationality='CN';
							val.biz_nationality_name='中国';
						}
						
						//先把这堆空数据，赋值上去，起码有字段
						val.address_detail='';
						val.province='';
						val.province_code=''
						val.city='';
						val.city_code='';

						that.$set(val, "cityList",[]);//赋值 市列表
						info_edit_do.china_Pai(that,applicant_list,val);
					}

				}else{//中国以外
					that.$set(val, "cityList",[]);//赋值 市列表

					// 没有 详情地址 address_detail 这个字段的，就是旧数据
					// 新数据，一定有 address_detail
					if(!$app.judgeData(val.address_detail)){
						old_data=true;
					}

					info_edit_do.china_Pai(that,applicant_list,val);
				}
			});


			if(old_data){
				// 旧数据提示语
				$app.alert('系统数据格式更新，请完善申请人信息');
			}
			
				
        }
	},
	
	// 中国+外国混排，会导致发明人顺序错乱，兼容处理
	china_Pai(that,appT,val){
		(that.$refs['common'].applicant_list).push(val);//赋值

		// 到了最后 重新排序
		if(appT.length==(that.$refs['common'].applicant_list.length)){
			console.log('专利详情，申请人信息，赋值成功 = ',that.$refs['common'].applicant_list);

			(that.$refs['common'].applicant_list).forEach((jar,r)=>{

				// 下面进入 省 + 市 的赋值 逻辑 必须一层包一层，有省，才有市
				// 外国+老数据 都是没有省代码 这个数据
				if($app.judgeData(jar.province_code)){
					that.$refs['common'].province_code_Fun(r,()=>{//省 中文名赋值
						if($app.judgeData(jar.city_code)){
							that.$refs['common'].city_code_Fun(r);//市 中文名赋值
						}
					});
				}
			});
		}

		
		
	},
};

// 表格 列 配置
export default info_edit_do;
